function selectTeam() {
	var len = document.forms[0].radio.length;
	for (var i = 0; i < len; i++) {
		if (document.forms[0].radio[i].checked) {
			var newWin = window.open("acceptChoose.do?method=emps&acceptChoose=" + 
				document.forms[0].radio[i].value, "_self");
		}
	}
} 
function selectHouqin() {
	var len = document.forms[0].radio.length;
	for (var i = 0; i < len; i++) {
		if (document.forms[0].radio[i].checked) {
			var newWin = window.open("acceptChoose.do?method=houqin&acceptChoose=" + 
				document.forms[0].radio[i].value, "_self");
		}
	}
} 
function changeDeptSelect() {

	var len = document.forms[0].leftSelect.length;
	//alert(len);
	var type=document.forms[0].type.value;
	for (var i = 0; i < len; i ++) {
		if (document.forms[0].leftSelect[i].selected) {
			window.location = "sms.do?method=queryParent&type=" +type+ 
				"&deptIdPath=" + document.forms[0].leftSelect[i].value + 
				"&employeeIDs=" + deptEmpRoleValue() + 
				"&employeeNames=" + deptEmpRoleView();
		}
	}
}

function chooseResultValue() {
	var choose = document.forms[0].acceptChoose.value;
	var chooseResultValue = "";
	switch (choose) {
		case "emp":
			chooseResultValue = "emp|" + deptEmpRoleValue();break;
	 	case "houqin":
			chooseResultValue = "houqin|" + deptEmpRoleValue();break;
		default:
			chooseResultValue = "unknow";break;
	}
	return chooseResultValue;
}

function chooseResultView() {
	var choose = document.forms[0].acceptChoose.value;
	var chooseResultView = "";
	switch (choose) {
		case "emp":
			chooseResultView = deptEmpRoleView();break;
		case "houqin":
			chooseResultView = deptEmpRoleView();break;			
		default:
			chooseResultView = "unknow";break;
	}
	return chooseResultView;
}

function submitThis() {
	opener.document.forms[0].acceptValue.value = chooseResultValue();

	opener.document.forms[0].acceptView.value = chooseResultView();

	window.close();
}
function deptEmpRoleValue() {
	var rightValue = "";
	var len = document.forms[0].rightList.length;
	if (len > 0) {
		rightValue = document.forms[0].rightList.options[0].value;
	}
	for (var i = 1; i < len; i++) {
		rightValue += "," + document.forms[0].rightList.options[i].value;
	}
	return rightValue;
}

function chooseResultLevelView() {
	var left, right;

	for (var i = 0; i < document.forms[0].leftList.length; i ++) {
		if (document.forms[0].leftList[i].selected) {
			left = document.forms[0].leftList[i].innerText;
		}
	}
	for (var i = 0; i < document.forms[0].rightList.length; i ++) {
		if (document.forms[0].rightList[i].selected) {
			right = document.forms[0].rightList[i].innerText;
		}
	}
		
	return document.forms[0].level.value + " " + right + " " + left;
}

function deptEmpRoleView() {
	var rightView = "", temp;
	var len = document.forms[0].rightList.length;
	if (len > 0) {
		temp = document.forms[0].rightList.options[0].innerText;
		rightView = temp = temp.substr(temp.lastIndexOf("-") + 1);
	}
	for (var i = 1; i < len; i++) {
		temp = document.forms[0].rightList.options[i].innerText;
		temp = temp.substr(temp.lastIndexOf("-") + 1);
		rightView += "," + temp;
	}
	return rightView;
}


function submitRightView() {
	var len = document.forms[0].rightList.length;
	if (len > 0) {
		document.forms[0].rightView.value = document.forms[0].rightList.options[0].innerText;
	}
	for (var i = 1; i < len; i++) {
		document.forms[0].rightView.value += "," + document.forms[0].rightList.options[i].innerText;
	}
}

function selectOne() {
	var len = document.forms[0].leftList.length;
	var f, op;
	for (var i = 0; i < len; i++) {
		op = document.forms[0].leftList.options[i];
	    if (op.selected) {
	    	if (!isRightExist(op.value)) {
		        f = new Option(op.innerText, op.value);
    	        document.forms[0].rightList.add(f);
			    document.forms[0].leftList.remove(i);
			}
			return;
	    }
    }
}

function deleteOne() {
  	var len = document.forms[0].rightList.length;
	var f, op;
	for (var i = 0; i < len; i++) {
		op = document.forms[0].rightList(i);
	    if (op.selected) {
			if (!isLeftExist(op.value)) {
		        f = new Option(op.innerText, op.value);
		        document.forms[0].leftList.options.add(f);
			    document.forms[0].rightList.remove(i);
			} else {
				document.forms[0].rightList.remove(i);
			}
			return;
	    } 
    }
}

function isRightExist(left) {
	for (var i = 0; i < document.forms[0].rightList.length; i++) {		
		if (document.forms[0].rightList.options[i].value == left) {
			//alert(document.forms[0].rightList.options[i].innerText + "......?);
			return true;
		}
	}

}

function isLeftExist(right) {
	for (var i = 0; i < document.forms[0].leftList.length; i++) {		
		if (document.forms[0].leftList.options[i].value == right) {
			return true;
		}
	}
}

function selectAll() {
	var len = document.forms[0].leftList.length;
	var f, op;
	for (var i=0; i<len; i++){
		op = document.forms[0].leftList.options[i];
		if (!isRightExist(op.value)) {
		    f = new Option(op.innerText, op.value);
    	    document.forms[0].rightList.options.add(f);
	    	document.forms[0].leftList.remove(i);
			len --;
			i --;
	    } else {
			document.forms[0].leftList.remove(i);
			len --;
			i --;
		}
    } 
}

function deleteAll() {
	var len = document.forms[0].rightList.length;
	var f, op;
	for (var i = 0; i < len; i++){
		op = document.forms[0].rightList(i);
		if (!isLeftExist(op.value)) {
		    f = new Option(op.innerText, op.value);
		    document.forms[0].leftList.options.add(f);
			document.forms[0].rightList.remove(i);
			len --;
			i --;
		} else {
			document.forms[0].rightList.remove(i);
			len --;
			i --;
		}
	}
}
  
function AddSubmit() {
    var selectedusername="";
	var selecteduserid="";
    var l=document.document.forms[0].rightList.length;
   //alert(document.document.forms[0].rightList(1).value);

	//alert(l);

	for (var i=0;i<l;i++) {
		if (i!=l-1)
			selecteduserid=selecteduserid+document.document.forms[0].rightList(i).value+",";
		else
			selecteduserid=selecteduserid+document.document.forms[0].rightList(i).value;
	}
	for (var i=0;i<l;i++) {
		if (i!=l-1)
				selectedusername=selectedusername+document.document.forms[0].rightList(i).innerText.substring(0,
				document.document.forms[0].rightList(i).innerText.indexOf("  ("))+",";
		else
				selectedusername=selectedusername+document.document.forms[0].rightList(i).innerText.substring(0,
				document.document.forms[0].rightList(i).innerText.indexOf("  ("));
	}
    	//alert(selectedusername);
	    //alert(selecteduserid);

    window.opener.document.frmAddAlarm.receiveUserName.value=selectedusername;
    window.opener.document.frmAddAlarm.receiveUserId.value=selecteduserid;

	window.close();
	//document.forms[0].submit();

}


function uploadDelete() {
	var len = document.forms[0].fileList.length;
	for (var i = 0; i < len; i ++) {
		if (document.forms[0].fileList[i].selected) {
			document.forms[0].fileList[i].remove(i);
		}
	}
}
